package com.example.sandbox.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sandbox.dto.MchApp;
import com.example.sandbox.mapper.MchAppMapper;
import com.example.sandbox.service.MchAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class MchAppServiceImpl extends ServiceImpl<MchAppMapper, MchApp> implements MchAppService {

    /**
     * 根据商户号和应用ID获取单个商户应用。
     */
    @Override
    public MchApp getOneByMch(String mchNo, String appId) {
        try {
            LambdaQueryWrapper<MchApp> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(MchApp::getMchNo, mchNo)
                    .eq(MchApp::getAppId, appId);
            return getOne(queryWrapper);
        } catch (Exception e) {
            log.error("获取商户应用失败，商户号：{}，应用ID：{}，错误信息：{}", mchNo, appId, e.getMessage());
            return null; // 或者抛出自定义异常
        }
    }
}